package cn.openea.perpartner.meily.web.service.impl;

import cn.openea.perpartner.meily.web.entity.Goods;
import cn.openea.perpartner.meily.web.entity.GoodsBusiness;
import cn.openea.perpartner.meily.web.entity.vo.GoodsBusinessVo;
import cn.openea.perpartner.meily.web.mapper.GoodsBusinessMapper;
import cn.openea.perpartner.meily.web.service.IGoodsBusinessService;
import cn.openea.perpartner.meily.web.service.IGoodsService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;


@Service("goodsBusinessService")
public class GoodsBusinessServiceImpl extends ServiceImpl<GoodsBusinessMapper, GoodsBusiness> implements IGoodsBusinessService {

    @Resource
    private IGoodsService goodsService;

    /**
     * 获取商品详情
     * @param vo
     * @return
     */
    @Override
    public GoodsBusiness getGoodsInfo(GoodsBusinessVo vo) {

        GoodsBusiness goodsBusiness = getById(vo.getBusinessId());
        if(goodsBusiness == null){
            // 如果 根据业务id 在 商品业务记录表 获取不到 商品记录时，需要去商品表取
            Goods goods = goodsService.getById(vo.getGoodsId());

            if(goods != null){
                goodsBusiness = new GoodsBusiness();
                BeanUtils.copyProperties(goods, goodsBusiness);
            }
        }
        return goodsBusiness;
    }
}